home *** CD-ROM | disk | FTP | other *** search
/ Clickx 36 / Clickx 36.iso / mac / assets / software / tuxpaint.dmg / Tux Paint.app / Contents / Frameworks / fonts.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-10-20  |  3.7 KB  |  139 lines

  1. /*
  2.   fonts.h
  3. */
  4.  
  5. #ifndef FONTS_H
  6. #define FONTS_H
  7.  
  8. // plan to rip this out as soon as it is considered stable
  9. //#define THREADED_FONTS
  10. #define FORKED_FONTS
  11. #ifdef WIN32
  12. #undef FORKED_FONTS
  13. #endif
  14.  
  15.  
  16.  
  17. #include "SDL.h"
  18. #include "SDL_ttf.h"
  19.  
  20. #include "compiler.h"
  21.  
  22. /* Disable threaded font loading on Windows */
  23. #if !defined(FORKED_FONTS) && !defined(WIN32)
  24. #include "SDL_thread.h"
  25. #include "SDL_mutex.h"
  26. #else
  27. /* This shouldn't really be here :-)
  28.  * Move into 'fonts.c' and the code in 'tuxpaint.c' 
  29.  * that uses this lot should be put into 'fonts.c' as well.
  30.  */
  31. #define SDL_CreateThread(fn,vp) (void*)(long)(fn(vp))
  32. #define SDL_WaitThread(tid,rcp) do{(void)tid;(void)rcp;}while(0)
  33. #define SDL_Thread int
  34. #define SDL_mutex int
  35. #define SDL_CreateMutex() 0    // creates in released state
  36. #define SDL_DestroyMutex(lock)
  37. #define SDL_mutexP(lock)    // take lock
  38. #define SDL_mutexV(lock)    // release lock
  39. #endif
  40.  
  41. extern SDL_Thread *font_thread;
  42.  
  43. extern volatile long font_thread_done, font_thread_aborted;
  44. extern volatile long waiting_for_fonts;
  45. extern int font_scanner_pid;
  46. extern int font_socket_fd;
  47.  
  48. extern int no_system_fonts;
  49. extern int was_bad_font;
  50.  
  51.  
  52. TTF_Font *BUGFIX_TTF_OpenFont206(const char *const file, int ptsize);
  53. #define TTF_OpenFont    BUGFIX_TTF_OpenFont206
  54.  
  55. TTF_Font *try_alternate_font(int size);
  56. TTF_Font *load_locale_font(TTF_Font * fallback, int size);
  57. int load_user_fonts(SDL_Surface * screen, void *vp);
  58.  
  59. #ifdef FORKED_FONTS
  60. void reliable_write(int fd, const void *buf, size_t count);
  61. void reliable_read(int fd, void *buf, size_t count);
  62. void run_font_scanner(SDL_Surface * screen);
  63. void receive_some_font_info(SDL_Surface * screen);
  64. #endif
  65.  
  66. //////////////////////////////////////////////////////////////////////
  67. // font stuff
  68.  
  69. // example from a Debian box with MS fonts:
  70. // start with 232 files
  71. // remove "Cursor", "Webdings", "Dingbats", "Standard Symbols L"
  72. // split "Condensed" faces out into own family
  73. // group by family
  74. // end up with 34 user choices
  75.  
  76. extern int text_state;
  77. extern unsigned text_size;
  78.  
  79. // nice progression (alternating 33% and 25%) 9 12 18 24 36 48 72 96 144 192
  80. // commonly hinted sizes seem to be: 9, 10, 12, 14, 18, 20 (less so), 24
  81. // reasonable: 9,12,18... and 10,14,18...
  82. static int text_sizes[] = { 9, 12, 18, 24, 36, 48,
  83.   56, 64, 96, 112, 128, 160
  84. };                // point sizes
  85.  
  86. #define MIN_TEXT_SIZE 0u
  87. #define MAX_TEXT_SIZE (sizeof text_sizes / sizeof text_sizes[0] - 1)
  88.  
  89. // for sorting through the font files at startup
  90. typedef struct style_info
  91. {
  92.   char *filename;
  93.   char *directory;
  94.   char *family;            // name like "FooCorp Thunderstruck"
  95.   char *style;            // junk like "Oblique Demi-Bold"
  96.   int italic;
  97.   int boldness;
  98.   int score;
  99.   int truetype;            // Is it? (TrueType gets priority)
  100. } style_info;
  101.  
  102. // user's notion of a font
  103. typedef struct family_info
  104. {
  105.   char *directory;
  106.   char *family;
  107.   char *filename[4];
  108.   TTF_Font *handle;
  109.   int score;
  110. } family_info;
  111.  
  112. extern TTF_Font *medium_font, *small_font, *large_font, *locale_font;
  113.  
  114. extern family_info **user_font_families;
  115. extern int num_font_families;
  116. extern int num_font_families_max;
  117.  
  118. extern style_info **user_font_styles;
  119. extern int num_font_styles;
  120. extern int num_font_styles_max;
  121.  
  122.  
  123. int compar_fontgroup(const void *v1, const void *v2);
  124. int compar_fontkiller(const void *v1, const void *v2);
  125. int compar_fontscore(const void *v1, const void *v2);
  126. void parse_font_style(style_info * si);
  127. void groupfonts_range(style_info ** base, int count);
  128. void dupe_markdown_range(family_info ** base, int count);
  129. void groupfonts(void);
  130. TTF_Font *getfonthandle(int desire);
  131. void loadfonts(SDL_Surface * screen, const char *const dir);
  132.  
  133. int do_surfcmp(const SDL_Surface * const *const v1,
  134.            const SDL_Surface * const *const v2);
  135. int surfcmp(const void *s1, const void *s2);
  136. int charset_works(TTF_Font * font, const char *s);
  137.  
  138. #endif
  139.